
package org.springxrsk.modules.resource.rule.sms;

import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springxrsk.core.redis.cache.XrskRedis;
import org.springxrsk.core.sms.QiniuSmsTemplate;
import org.springxrsk.core.sms.SmsTemplate;
import org.springxrsk.core.sms.props.SmsProperties;
import org.springxrsk.modules.resource.pojo.entity.Sms;
import org.springxrsk.modules.resource.rule.context.SmsContext;

/**
 * 七牛云短信构建类
 *
 * @author
 */
@LiteflowComponent(id = "qiniuSmsRule", name = "七牛SMS构建")
public class QiniuSmsRule extends NodeComponent {

	@Override
	public void process() throws Exception {
		// 获取上下文
		SmsContext contextBean = this.getContextBean(SmsContext.class);
		Sms sms = contextBean.getSms();
		XrskRedis XrskRedis = contextBean.getXrskRedis();

		SmsProperties smsProperties = new SmsProperties();
		smsProperties.setTemplateId(sms.getTemplateId());
		smsProperties.setAccessKey(sms.getAccessKey());
		smsProperties.setSecretKey(sms.getSecretKey());
		smsProperties.setSignName(sms.getSignName());
		Auth auth = Auth.create(smsProperties.getAccessKey(), smsProperties.getSecretKey());
		SmsManager smsManager = new SmsManager(auth);
		SmsTemplate smsTemplate = new QiniuSmsTemplate(smsProperties, smsManager, XrskRedis);

		// 设置上下文
		contextBean.setSmsTemplate(smsTemplate);

	}
}
